package artid.com.arttogoa.util;

import android.annotation.SuppressLint;
import android.content.Context;
import android.util.DisplayMetrics;
import android.view.Gravity;
import android.view.WindowManager;
import android.widget.Toast;
/**
 * 
 *    
 * 类名称：ToastUtil   
 * 类描述：  
 * 创建人：耿卫斌 
 *
 */
public class ToastUtil {
	private static  Toast toast=null;
	/**自定义Toast
	 * 短时间显示Toast 作用:不重复弹出Toast,如果当前有toast正在显示，则先取消
	 * 
	 * @param info
	 *            显示的内容
	 */
	@SuppressLint("InflateParams") 
	public static void toast(Context context,String info) {
		if (toast != null) {
			toast.cancel();
			toast=null;
		}
		toast = new Toast(context);
		toast=android.widget.Toast.makeText(context, info, Toast.LENGTH_SHORT);
		toast.setGravity(Gravity.TOP, 0,getScreenHeight(context)/2);
		toast.show();
	}

	public static void commonToast(Context context,String info) {
		if (toast != null) {
			toast.cancel();
			toast=null;
		}
		toast = new Toast(context);
		toast=android.widget.Toast.makeText(context, info, Toast.LENGTH_SHORT);
		toast.show();
	}

	/**
	 * 获得屏幕高度
	 * 
	 * @param context
	 * @return
	 */
	public static int getScreenHeight(Context context)
	{
		WindowManager wm = (WindowManager) context
				.getSystemService(Context.WINDOW_SERVICE);
		DisplayMetrics outMetrics = new DisplayMetrics();
		wm.getDefaultDisplay().getMetrics(outMetrics);
		return outMetrics.heightPixels;
	}
}
